//
//  WXPMineSettingView.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/25.
//
//

#import "WXPMineSettingView.h"

@interface WXPMineSettingView ()

@end

@implementation WXPMineSettingView

#pragma mark - lazy
- (UIView *)viewBack
{
    if (_viewBack == nil) {
        _viewBack = [UIView  new];
        _viewBack.backgroundColor = COLOR_WHITE;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
        _viewBack.widthHeight = XY(SCREEN_WIDTH-2*LEFT_MARDIN, 0);
        _viewBack.userInteractionEnabled = true;
    }
    return  _viewBack;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.width = SCREEN_WIDTH;
        [self addSubView];
    }
    return self;
}

//添加subview
- (void)addSubView{
    NSMutableArray * list = [NSMutableArray new];
    [list addObject:^(void){
        ModelBtn * model = [ModelBtn new];
        model.title = @"Cuenta bancaria";
        model.imageName = @"icon-mine-bankcard";
        return model;
    }()];
    [list addObject:^(void){
        ModelBtn * model = [ModelBtn new];
        model.title = @"Acuerdo de privacida";
        model.imageName = @"icon-mine-agreement";
        return model;
    }()];
    [list addObject:^(void){
        ModelBtn * model = [ModelBtn new];
        model.title = @"Configuración";
        model.imageName = @"icon-mine-setting";
        return model;
    }()];
    
    for (int i = 0; i < list.count; i ++) {
        ModelBtn * model = list[i];
        UIButton * view = [UIButton new];
        view.tag = i+1;
        [view addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        view.widthHeight = XY(self.viewBack.width, 53);
        view.leftTop = XY(0, 8+view.height*i);
        [self.viewBack addSubview:view];
        view.userInteractionEnabled = true;
        UIImageView * image = [UIImageView new];
        image.widthHeight = XY(18, 18);
        image.image = [UIImage imageNamed:model.imageName];
        image.leftCenterY = XY(LEFT_MARDIN, view.height/2);
        [view addSubview:image];
        UILabel * label = [UILabel new];
        [GlobalMethod setLabel:label widthLimit:0 isBold:true fontNum:14 textColor:COLOR_BLACK text:model.title];
        label.leftCenterY = XY(image.right+12, image.centerY);
        [view addSubview:label];
        UIImageView * imageArrow = [UIImageView new];
        imageArrow.widthHeight = XY(14, 14);
        imageArrow.image = [UIImage imageNamed:@"icon-arrow-detail"];
        imageArrow.rightCenterY = XY(self.viewBack.width-image.left, view.height/2);
        [view addSubview:imageArrow];
        if(i == list.count-1){
            self.viewBack.height = view.bottom+8;
        }
    }
    self.viewBack.centerXTop = XY(SCREEN_WIDTH/2, 0);
    [self addSubview:self.viewBack];
    self.height = self.viewBack.bottom+LEFT_MARDIN;
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [Global_Nav pushVCName:@"WXPBankCardVC" animated:true];
        }
            break;
        case 2:
        {
            [Global_Nav pushVCName:@"WXPPrivacyAgreementVC" animated:true];
        }
            break;
        case 3:
        {
            [Global_Nav pushVCName:@"WXPSettingVC" animated:true];
        }
            break;
        default:
            break;
    }
}

@end
